package com.example.hospital.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hospital.dto.AppointmentQuery;
import com.example.hospital.entity.Appointment;
import com.example.hospital.service.AppointmentService;
import com.example.hospital.mapper.AppointmentMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Oreki
 * @description 针对表【appointment】的数据库操作Service实现
 * @createDate 2024-12-27 16:53:20
 */
@Service
public class AppointmentServiceImpl extends ServiceImpl<AppointmentMapper, Appointment>
        implements AppointmentService {

    @Override
    public List<Appointment> listAppointments(AppointmentQuery appointmentQuery) {
        if (appointmentQuery == null) {
            return this.list();
        }
        Integer patientId = appointmentQuery.getPatientId();
        Integer doctorId = appointmentQuery.getDoctorId();
        String status = appointmentQuery.getStatus();
        String paymentStatus = appointmentQuery.getPaymentStatus();
        String startTime = appointmentQuery.getStartTime();
        String endTime = appointmentQuery.getEndTime();
        return this.lambdaQuery()
                .eq(patientId != null, Appointment::getPatientId, patientId)
                .eq(doctorId != null, Appointment::getDoctorId, doctorId)
                .eq(StrUtil.isNotEmpty(status), Appointment::getStatus, status)
                .eq(StrUtil.isNotEmpty(paymentStatus), Appointment::getPaymentStatus, paymentStatus)
                .ge(StrUtil.isNotEmpty(startTime), Appointment::getAppointmentTime, startTime)
                .le(StrUtil.isNotEmpty(endTime), Appointment::getAppointmentTime, endTime)
                .list();
    }
}




